//
//  SliderLabelContainer.m
//  WeightMaster
//
//  Created by maoyu on 15/8/14.
//  Copyright (c) 2015年 buddysoft. All rights reserved.
//

#import "SliderLabelContainer.h"
#import "BDFoundation.h"

#define DIGIT_COUNT 10

@interface SliderLabelContainer() {
    UIScrollView * _scrollView;
}

@end

@implementation SliderLabelContainer

- (id)initWithFrame:(CGRect)frame  {
    if (self = [super initWithFrame:frame]) {
        _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        _scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)*DIGIT_COUNT);
        
        for (NSInteger index = 0; index<DIGIT_COUNT; index++) {
            UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) * index, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))];
            label.text = [NSString stringWithFormat:@"%ld",(long)index];
            label.textAlignment = NSTextAlignmentCenter;
            label.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:50.0];
            label.textColor = [UIColor whiteColor];
            label.shadowColor = RGB(82, 82, 97);
            label.shadowOffset = CGSizeMake(0.5, 0.5);
            [_scrollView addSubview:label];
        }
        
        [self addSubview:_scrollView];
    }
    
    return self;
}

- (void)scrollToNum:(NSInteger)num {
    if (SingleDigitType == self.containerType) {
        [UIView animateWithDuration:0.85 animations:^{
            _scrollView.contentOffset = CGPointMake(0, CGRectGetHeight(self.bounds) * num);

        }];
    }else if (TensDigitType == self.containerType) {
        [UIView animateWithDuration:0.95 animations:^{
            _scrollView.contentOffset = CGPointMake(0, CGRectGetHeight(self.bounds) * num);
            
        }];
    }else if (HundredDigitType == self.containerType) {
        [UIView animateWithDuration:1.0 animations:^{
            _scrollView.contentOffset = CGPointMake(0, CGRectGetHeight(self.bounds) * num);
            
        }];
    }else if (DecimalDigitType == self.containerType) {
        [UIView animateWithDuration:0.75 animations:^{
            _scrollView.contentOffset = CGPointMake(0, CGRectGetHeight(self.bounds) * num);
            
        }];
    }
}

@end
